const router = require('koa-router')()
router.prefix('/users')
const {
    find,
    findById,
    createUser,
    update,
    deleteUser,
    login,
    checkOwner,
    listFollowing,
    checkUserExist,
    follow,
    unFollow,
    listFollowers,
    listFollowingTopic,
    followTopic,
    unFollowTopic,
    listQuestions,
    listLikingAnswers, likingAnswer, unlikingAnswer,
    listDislikingAnswers, dislikingAnswer, undislikingAnswer,
    listCollectingQuestions, collectingQuestion, uncollectingQuestion
} = require("../controller/user")
const auth = require("../utils/auth")
const { checkTopicExist } = require("../controller/topic")
const { checkAnswersExist } = require("../controller/answers")
const { checkQuestionExist } = require("../controller/questions")

// 用户列表接口
router.get('/', find)

// 使用Id获取用户信息
router.get("/getUser", auth, findById)

// 创建一个用户
router.post("/create", createUser)

// 更新用户信息
router.patch("/update/:id", auth, checkOwner, update)

// 删除一个用户
router.delete("/delete/:id", auth, checkOwner, deleteUser)

// 登录接口
router.post("/login", login)

// 获取用户关注列表
router.get("/:id/following", listFollowing)

// 关注别人接口
router.put("/following/:id", auth, checkUserExist, follow)

// 取消关注用户接口
router.delete("/following/:id", auth, checkUserExist, unFollow)

// 获取粉丝列表
router.get("/:id/followers", listFollowers)

// 获取用户关注话题列表
router.get("/:id/followingTopic", listFollowingTopic)

// 关注一个话题
router.put("/followingTopic/:id", auth, checkTopicExist, followTopic)

// 取消关注一个话题
router.delete("/followingTopic/:id", auth, checkTopicExist, unFollowTopic)

// 查询用户的问题列表
router.get("/:id/questions", listQuestions)

// 获取用户赞回答列表
router.get("/:id/likingAnswers", listLikingAnswers)

//赞一个回答
router.put("/likingAnswers/:id", auth, checkAnswersExist, likingAnswer, undislikingAnswer)

// 取消赞一个回答
router.delete("/likingAnswers/:id", auth, checkAnswersExist, unlikingAnswer)

// 获取用户踩回答列表
router.get("/:id/dislikingAnswers", listDislikingAnswers)

//踩一个回答
router.put("/dislikingAnswers/:id", auth, checkAnswersExist, dislikingAnswer, unlikingAnswer)

// 取消踩一个回答
router.delete("/dislikingAnswers/:id", auth, checkAnswersExist, undislikingAnswer)

// 获取用户收藏问题列表
router.get("/:id/collectingQuestions", listCollectingQuestions)

//收藏一个问题
router.put("/collectingQuestions/:id", auth, checkQuestionExist, collectingQuestion)

// 取消收藏一个问题
router.delete("/collectingQuestions/:id", auth, checkQuestionExist, uncollectingQuestion)



module.exports = router
